package com.ruoyi.web.controller.safety;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SnowflakeIdUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safety.domain.SafetyPointInfo;
import com.ruoyi.safety.service.ISafetyPointInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测点基本信息Controller
 *
 * @author ruoyi
 * @date 2024-10-30
 */
@RestController
@RequestMapping("/safety/pointInfo")
public class SafetyPointInfoController extends BaseController
{
    @Autowired
    private ISafetyPointInfoService safetyPointInfoService;

    /**
     * 查询测点基本信息列表
     */
    //@PreAuthorize("@ss.hasPermi('safety:info:list')")
    @GetMapping("/list")
    @ApiOperation("测点基本信息")
    public TableDataInfo list(SafetyPointInfo safetyPointInfo)
    {
        startPage();
        List<SafetyPointInfo> list = safetyPointInfoService.selectSafetyPointInfoList(safetyPointInfo);
        return getDataTable(list);
    }

    /**
     * 导出测点基本信息列表
     */
    @PreAuthorize("@ss.hasPermi('safety:info:export')")
    @Log(title = "测点基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SafetyPointInfo safetyPointInfo)
    {
        List<SafetyPointInfo> list = safetyPointInfoService.selectSafetyPointInfoList(safetyPointInfo);
        ExcelUtil<SafetyPointInfo> util = new ExcelUtil<SafetyPointInfo>(SafetyPointInfo.class);
        util.exportExcel(response, list, "测点基本信息数据");
    }

    /**
     * 获取测点基本信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('safety:info:query')")
    @GetMapping(value = "/{pointCode}")
    public AjaxResult getInfo(@PathVariable("pointCode") String pointCode)
    {
        return success(safetyPointInfoService.selectSafetyPointInfoByPointCode(pointCode));
    }

    /**
     * 新增测点基本信息
     */
    @PreAuthorize("@ss.hasPermi('safety:info:add')")
    @Log(title = "测点基本信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SafetyPointInfo safetyPointInfo)
    {
        long id = new SnowflakeIdUtils(5, 8).nextId();
        safetyPointInfo.setExtend1(String.valueOf(id));
        return toAjax(safetyPointInfoService.insertSafetyPointInfo(safetyPointInfo));
    }

    /**
     * 修改测点基本信息
     */
    @PreAuthorize("@ss.hasPermi('safety:info:edit')")
    @Log(title = "测点基本信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SafetyPointInfo safetyPointInfo)
    {
        return toAjax(safetyPointInfoService.updateSafetyPointInfo(safetyPointInfo));
    }

    /**
     * 删除测点基本信息
     */
    @PreAuthorize("@ss.hasPermi('safety:info:remove')")
    @Log(title = "测点基本信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{pointCodes}")
    public AjaxResult remove(@PathVariable String[] pointCodes)
    {
        return toAjax(safetyPointInfoService.deleteSafetyPointInfoByPointCodes(pointCodes));
    }
}
